package com.wn55.hrms.web.controller;

import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.RecruitRequire;
import com.wn55.hrms.service.RecruitRequireService;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author Mr.bai~
 * @version 1.0
 * @date 2022/5/1 17:56
 */

@RestController
@RequestMapping("require")
@Api(value = "本接口是用来操作需求功能")
public class RecruitRequireController {

    @Autowired
    RecruitRequireService recruitRequireService;


    @GetMapping("/requireList")
    @ApiOperation(value = "分页查询管理员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "int",name = "now",value="查询当前页",required = false,defaultValue = "1"),
            @ApiImplicitParam(paramType = "query",dataType = "int",name="size",value = "每页显示多少条",required = false,defaultValue = "2"),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="deptName",value = "需求部门名称",required = false),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="requireType",value = "需求类型",required = false),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="postName",value = "需求岗位名称",required = false),
    })
    public ResultResponse<PageInfo<RecruitRequire>> requireList(
            @RequestParam(value = "now", defaultValue = "1") Integer now,
            @RequestParam(value = "size", defaultValue = "2") Integer size,
            String deptName, String requireType, String postName) {
        System.out.println(deptName);
        System.out.println(requireType);
        System.out.println(postName);
        ResultResponse<PageInfo<RecruitRequire>> result = null;
        try {
            PageInfo<RecruitRequire> pageInfo = recruitRequireService.queryRequire(now, size, deptName, requireType, postName);
            result = new ResultResponse<>(200, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(404, "查询失败");
        }
        return result;
    }
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据标识ID删除管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "int",name = "id",value = "管理员的ID标识")
    })
    public ResultResponse<Void> delete(@PathVariable("id")int id){
        System.out.println(id);

        ResultResponse<Void> result = null;

        try {
            recruitRequireService.removeBykey(id);
            result = new ResultResponse<>(200, "删除角色成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "删除角色失败!");
        }
        return result;
    }

    @PostMapping("/addRequire")
    @ApiImplicitParam(value = "添加新的需求")
    public ResultResponse<Void> addRequire(@RequestBody RecruitRequire recruitRequire) {
        ResultResponse<Void> result = null;
        try {
            recruitRequireService.addRequire(recruitRequire);

            result = new ResultResponse<>(200, "添加角色成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "添加角色失败!");
        }
        return result;
    }
    @PutMapping("/modify")
    @ApiOperation(value = "根据ID修需求")
    public ResultResponse<Void> editRequire(@RequestBody RecruitRequire RecruitRequire){
        ResultResponse<Void> result = null;
        try{

            recruitRequireService.modify(RecruitRequire);
            result = new ResultResponse<>(200,"修改成功");
        }catch (Exception e){
            e.printStackTrace();
            result = new ResultResponse<>(404,"修改失败");
        }
        return result;
    }
}
